
#include "StdAfx.h"
#include "TickSaver.h"

TickSaver::TickSaver(){
}

TickSaver::~TickSaver(){
}

void TickSaver::reset( unsigned int size ){
	if( size )
		ticks_.reserve( size );

	for( size_t i = 0 ; i < size ; i++ )
		ticks_.push_back( 0 );

	int size_ = ticks_.capacity();
}

void TickSaver::store_tick( unsigned int idx, unsigned __int64 value_tick ){
	ticks_[ idx ] = value_tick;
}

bool TickSaver::is_elapsed( unsigned int idx, int value_tick, unsigned __int64 current_tick ){
	IS_NULL_RETURN( value_tick, false );

	if(! current_tick )
		current_tick = getTick();	

	unsigned __int64 store_tick = ticks_[ idx ];
	store_tick += (unsigned __int64)value_tick;

	if( current_tick < store_tick )
		return false;
	return true;
}

unsigned __int64 TickSaver::get_tick( unsigned int idx ){
	return ticks_[ idx ];
}

void TickSaver::store_sec( unsigned int idx, int value_sec ){
	ticks_[ idx ] = (unsigned __int64)value_sec;
}

bool TickSaver::is_elapsed_sec( unsigned int idx, int value_sec, int current_sec ){
	IS_NULL_RETURN( value_sec, false );

	if(! current_sec )
		current_sec = (int)time( 0 );	

	size_t store_sec = (size_t)ticks_[ idx ];
	store_sec += (size_t)value_sec;

	if( (size_t)current_sec < store_sec )
		return false;
	return true;
}

int TickSaver::get_sec( unsigned int idx ){
	return ticks_[ idx ];
}
